package HLLib.userControl.HLPanelPickUp;

import javax.microedition.lcdui.Image;

import HLLib.base.HLGraphics;
import HLLib.base.HLGraphics_H;
import HLLib.base.HLImage;
import HLLib.base.HLString;
import HLLib.control.HLPanel;
import HLLib.control.HLPhotoFrame;
import HLLib.handfere.HLCommunityData.HLMessage.HLMessageSayHello;

public class HLSayHelloMsgPanel extends HLPanel {
    public static final int PHOTO_X = 3;

    public static final int PHOTO_Y = 8;

    public static final int PHOTO_TO_TEXT = 10;

    public static final int TEXT_Y = 2;

    HLPhotoFrame photoFrame;

    int xText;

    public int selectColor = 0xffff00;

    public int color = 0xffecf3fd;

    public HLMessageSayHello msg;

    Image img;

    int iconHeight;

    public HLSayHelloMsgPanel(HLMessageSayHello msg, Image img) {
        dock = DOCK_STYLE_TOP;
        tabelStop = true;
        this.img = img;
        this.msg = msg;
        this.backcolor = -1;
        photoFrame = new HLPhotoFrame(msg.icon, PHOTO_X, PHOTO_Y);
        Add(photoFrame);
        iconHeight = Math.max(HLGraphics.StringHeight(), msg.typeIcon.getHeight());

        xText = PHOTO_X + photoFrame.width + PHOTO_TO_TEXT;

        this.height = (Math.max(TEXT_Y + HLGraphics.StringHeight() + TEXT_Y + iconHeight + TEXT_Y, TEXT_Y * 2 + photoFrame.height));

    }

    public void Logic() {
        super.Logic();
        if (IsFocus()) {
            RefreshEvent(GetScreenX(), GetScreenY(), GAME_BUTTON_ACTION);
        }
    }

    public void Refresh() {
        super.Refresh();

    }

    public void Render(HLGraphics g) {
        // super.Render(g);
        int screenX = GetScreenX();
        int screenY = GetScreenY();
        g.FillRect(screenX, screenY, width, height, 0xffffff);
        if (IsFocus()) {
            // g.DrawImageFillRect(new HLImage(img[1]), screenX, screenY, width,
            // img[1].getHeight(), HLGraphics_H.TRANS_NONE);
            // g.DrawImageFillRect(new HLImage(img[0]), screenX, screenY +
            // height - img[0].getHeight(), width, img[1].getHeight(),
            // HLGraphics_H.TRANS_NONE);
            g.FillRect(screenX, screenY, width, height, HLPanelGroup.SELECTED_COLOR);// d0d9f2);//0xd0ebf2);
            g.DrawImage(new HLImage(img), screenX + width - img.getWidth() - 5, screenY + (height - img.getHeight() >> 1), HLGraphics_H.TRANS_NONE);
        } else {

        }
        int offsetX = screenX + xText;
        int offsetY = screenY + TEXT_Y;

        g.DrawString(new HLString(msg.nickName), offsetX, offsetY, 0xff0000ff, 0, TEXT_STYLE_NORMAL);
        g.DrawString(new HLString(msg.dateline), offsetX + HLGraphics.StringWidth1(msg.nickName) + 15, offsetY, 0xff4b4b4b, 0, TEXT_STYLE_NORMAL);

        offsetY += HLGraphics.StringHeight() + TEXT_Y;

        g.DrawImage(new HLImage(msg.typeIcon), offsetX, offsetY + iconHeight - msg.typeIcon.getHeight(), HLGraphics_H.TRANS_NONE);
        g.DrawString(new HLString(msg.toString()), offsetX + msg.typeIcon.getWidth() + 2, offsetY + iconHeight - HLGraphics.StringHeight(), 0, 0, TEXT_STYLE_NORMAL);

        photoFrame.Render(g);

    }

}
